﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ToolBox
{
    public partial class Main : Form
    {
        public string SearchTerm;        
        public bool forSearch;
        
        public Main()
        {
            InitializeComponent();
        }

        private void cmsMain_Opening(object sender, CancelEventArgs e)
        {
            
        }

        public void ShutDown()
        {
            if (niMain.Visible)
            {
                niMain.Visible = false;
            }
            Application.Exit();
        }

        private void cmiExit_Click(object sender, EventArgs e)
        {
            this.ShutDown();
        }

        private void Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true;
                this.Hide();
            }
        }

        private void Restore()
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
                this.WindowState = FormWindowState.Normal;
            }
            this.Visible = true;
        }

        private void niMain_DoubleClick(object sender, EventArgs e)
        {
            SearchForm mySearchForm = new SearchForm();
            mySearchForm.SearchType = 999;
            mySearchForm.Show();
        }

        private void cmiDefaultGoogleSearch_Click(object sender, EventArgs e)
        {
            this.cmiDefaultGoogleSearch.TextBox.SelectAll();
        }

        private void cmiDefaultGoogleSearch_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                SearchForm mySearchForm = new SearchForm();
                mySearchForm.SearchType = 1;
                mySearchForm.SearchTerm = this.cmiDefaultGoogleSearch.TextBox.Text;
                mySearchForm.Show();
                this.cmiDefaultGoogleSearch.TextBox.Text = "Google";
            }
        }

        private void cmiLiveSearch_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                SearchForm mySearchForm = new SearchForm();
                mySearchForm.SearchType = 2;
                mySearchForm.SearchTerm = this.cmiLiveSearch.TextBox.Text;
                mySearchForm.Show();
                this.cmiLiveSearch.TextBox.Text = "Live Search";
            }
        }

        private void cmiAbout_Click(object sender, EventArgs e)
        {
            AboutBox myAboutBox = new AboutBox();
            myAboutBox.Show();
        }

        private void cmiLiveSearch_Click(object sender, EventArgs e)
        {
            this.cmiLiveSearch.SelectAll();
        }

        private void cmiShowBrowser_Click(object sender, EventArgs e)
        {
            SearchForm mySearchForm = new SearchForm();
            mySearchForm.SearchType = 999;
            mySearchForm.Show();
        }

        private void googleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.googleToolStripMenuItem.TextBox.SelectAll();
        }

        private void googleToolStripMenuItem_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                SearchForm mySearchForm = new SearchForm();
                mySearchForm.SearchType = 3;
                mySearchForm.SearchTerm = this.googleToolStripMenuItem.TextBox.Text;
                mySearchForm.Show();
                this.googleToolStripMenuItem.TextBox.Text = "Google Maps";
            }

        }

        private void cmiWPSearch_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                SearchForm mySearchForm = new SearchForm();
                mySearchForm.SearchType = 4;
                mySearchForm.SearchTerm = this.cmiWPSearch.TextBox.Text;
                mySearchForm.Show();
                this.cmiWPSearch.TextBox.Text = "Wikipedia";
            }
        }
                

        private void Main_Load(object sender, EventArgs e)
        {
            forSearch = false;
        }

        private void Main_VisibleChanged(object sender, EventArgs e)
        {
            
        }

        private void cmiMultiSearch_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                this.SearchTerm = cmiMultiSearch.TextBox.Text;
                this.myGoogleBrowser.Navigate("http://www.google.com/search?q=" + this.SearchTerm);
                this.liveBrowser.Navigate("http://search.msn.com/results.aspx?q=" + this.SearchTerm);
                this.wikiBrowser.Navigate("http://en.wikipedia.org/wiki/Special:Search?search=" + this.SearchTerm + "&fulltext=Search");
                this.WindowState = FormWindowState.Normal;
                this.cmiMultiSearch.TextBox.Text = "MultiSearch";
            }
        }

        private void cmiMail_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                SearchForm mySearchForm = new SearchForm();
                mySearchForm.SearchType = 5;
                mySearchForm.SearchTerm = this.cmiMail.TextBox.Text;
                mySearchForm.Show();
                this.cmiMail.TextBox.Text = "GMail";
            }
        }

        private void cmiMultiSearch_Click(object sender, EventArgs e)
        {
            this.cmiMultiSearch.TextBox.SelectAll();
        }

        private void cmiMail_Click(object sender, EventArgs e)
        {
            this.cmiMail.TextBox.SelectAll();
        }

        private void cmiWPSearch_Click(object sender, EventArgs e)
        {
            this.cmiWPSearch.TextBox.SelectAll();
        }

        
    }
}
